package org.clatt.anki.wx.service;

import org.clatt.anki.db.domain.AnkiRegion;
import org.clatt.anki.db.service.AnkiRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zhy
 * @date 2019-01-17 23:07
 **/
@Component
public class GetRegionService {

	@Autowired
	private AnkiRegionService regionService;

	private static List<AnkiRegion> ankiRegions;

	protected List<AnkiRegion> getAnkiRegions() {
		if(ankiRegions==null){
			createRegion();
		}
		return ankiRegions;
	}

	private synchronized void createRegion(){
		if (ankiRegions == null) {
			ankiRegions = regionService.getAll();
		}
	}
}
